package com.hxgis.oc.config;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class OConfig {
    @Getter
    private static OConfigInstance config;

    @Autowired
    private void setConfig(OConfigInstance value)
    {
        config = value;
    }

    public static LocalDateTime Beijing2UTC(LocalDateTime time)
    {
        return time.minusHours(8);
    }

    public static Long genTimeStampFid(LocalDateTime time)
    {
        return Long.parseLong(formatQueryString(time));
    }

    public static Long genUTCTimeStampFid(LocalDateTime time)
    {
        return Long.parseLong(formatUTCQueryString(time));
    }

    public static String formatQueryString(LocalDateTime time)
    {
        return DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(time);
    }

    public static String formatUTCQueryString(LocalDateTime time)
    {
        return DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(Beijing2UTC(time));
    }

    public static String formatLogString(LocalDateTime time,boolean convert2Beijing)
    {
        return DateTimeFormatter.ofPattern("yyyy-MM-dd-HH").format(convert2Beijing ? time.plusHours(8) : time);
    }
}
